#ifndef MYSQLCONNECTIONPOOL_H
#define MYSQLCONNECTIONPOOL_H

#include <mysql/mysql.h>  
#include <vector>  
#include <mutex>  
#include <condition_variable>  
#include <stdexcept>  
#include <memory>  
  
class MySQLConnectionPool {
public:  
    MySQLConnectionPool(const char* host, const char* user, const char* password, const char* db, int port, int poolSize);  
    ~MySQLConnectionPool();  
  
    // 获取一个连接，如果池中没有可用连接，则阻塞直到有连接可用  
    MYSQL* getConnection();  
  
    // 释放一个连接回池中  
    void releaseConnection(MYSQL* conn);  
  
private:  
    std::vector<MYSQL*> connections_;  
    std::mutex mtx_;  
    std::condition_variable cv_;  
    const char* host_;  
    const char* user_;  
    const char* password_;  
    const char* db_;  
    int port_;  
    int poolSize_;  
    int availableConnections_;  
  
    // 创建新连接  
    MYSQL* createConnection();  
};  
  

#endif